<?php
namespace app\common\model;

use think\Model;
use app\common\model\Industry;

class Industry extends Model
{

	public function exhibitions()
	{
		return $this->hasMany('IndustryExhibition','industry_id');
	}

	public function GetPidAttr($value)
	{
		$data = $this->field('id,name')->select();
		 $status = [0=>'顶级分类'];
		foreach ($data as $key => $va) {
			 $status[$va['id']] = $va['name'];
		}
		// dump($status);
		return $status[$value];

	}


	public function detail($id)
	{
		$where = [
            // ['status' ,'eq', 1],
            ['id' ,'eq', $id]
        ];
        $result = $this->where($where)->find();
        return $result;
	}

    public function sonlist($id)
    {
        $where = [];
        // dump($id);
        $where[] = ['pid', 'eq', $id];
        $where[] = ['status', 'eq', 1];
        $order = 'sorts desc';
        // $list =  $this->where($where)->order($order)->select();
        $list =  $this->where($where)->order($order)->select();
        // dump($list);
        return $list;
    }
}